USE [AnotherSuccessfulProcedure]

IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[PlayerClassStatsSelectByPlayerId]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
BEGIN
	DROP PROCEDURE dbo.PlayerClassStatsSelectByPlayerId
END


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Neil Wilson
-- Create date: 09/10/08
-- Description:	PlayerClassStats Table Select By PlayerId
-- =============================================
CREATE PROCEDURE PlayerClassStatsSelectByPlayerId

			@PlayerId varchar(30),
			@ClassId int
	
AS
BEGIN

DECLARE 
		@ReturnName varchar(50),
		@Points varchar(8),
		@Kills int,
		@Assists int,
		@Deaths int,
		@KillDeathRatio varchar(8),
		@Dominations int,
		@Ubers int,
		@Healing float,
		@TimesPlayed int
		
		

select @Assists = COUNT(AssistId) FROM Assists WHERE assister_PlayerId = @PlayerId and ClassId = @ClassId

SELECT @ReturnName = ClassLongName From classes
WHERE ClassId = @ClassId




select @Kills = COUNT(KillId) FROM Kills WHERE Attacker_PlayerId = @PlayerId  and Attacker_ClassId = @ClassId

select @Deaths = COUNT(KillId) FROM Kills WHERE Victim_PlayerId = @PlayerId
	AND Victim_classId = @ClassId
	
select @Ubers  = COUNT(ChargeId) FROM MedicCharge
		WHERE PlayerId = @PlayerId


select @Dominations = Count(DominationId) FROM Dominations
WHERE Attacker_playerId = @PlayerId


SET @Healing = 0.0

SET @TimesPlayed = 0

select @ReturnName as [ClassName], 0 as [Points], 
		@TimesPlayed as [TimesPlayed],
		@Kills as [Kills], @Assists as [Assists], 
		@Deaths as [Deaths], 0.0 as [KillDeathRatio],
		@Dominations as [Dominations], @Ubers as [Ubers],
		@PlayerId as [PlayerId], @ClassId as [ClassId]

END
GO

--    PlayerClassStatsSelectByPlayerId 'STEAM_0:0:13191839', 7



